<?php

namespace app\store\model\store;

use app\common\model\store\StoreNotice as StoreNoticeModel;

/**
 * 商家门店模型
 * Class Shop
 * @package app\store\model\store
 */
class Letter extends StoreNoticeModel
{
    /**
     * 获取列表数据
     * @param array $param
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList($param = [])
    {
        // 检索查询条件
        !empty($param) && $this->setWhere($param);
        // 获取数据列表
        return $this->order(['is_see' => 'asc', 'create_time' => 'desc'])
            ->paginate(10, false, [
                'query' => \request()->request()
            ]);

    }


    /**
     * 设置列表查询条件
     * @param array $param
     * @return $this
     */
    private function setWhere($query = [])
    {
        if (isset($query['start_time']) && !empty($query['start_time'])) {
            $this->where('create_time', '>=', strtotime($query['start_time']));
        }
        if (isset($query['end_time']) && !empty($query['end_time'])) {
            $this->where('create_time', '<', strtotime($query['end_time']) + 86400);
        }
        if (isset($query['type']) && $query['type'] > 0) {

            $this->where('type', '=', (int)$query['type']);
        }
        if (isset($query['is_see']) && $query['is_see'] > -1) {
            $this->where('is_see', '=', (int)$query['is_see']);
        }


    }



    /**
     * 已读
     * @return false|int
     */
    public function setSee()
    {
        return $this->save(['is_see' => 1]);
    }

    /**
     * 软删除
     * @return false|int
     */
    public function setDelete()
    {
        return $this->delete();
    }




}